/**
 *  Copyright (C) 2008-2013  Telosys project org. ( http://www.telosys.org/ )
 *
 *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          http://www.gnu.org/licenses/lgpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.telosys.common.xml.mapper;

import java.io.PrintWriter;

import org.telosys.common.val.DoubleValue;
import org.telosys.common.xml.IXmlWrapper;
import org.telosys.common.xml.XmlWrapperAncestor;

/**
 * XML mapper implementation for DoubleValue
 * 
 * @author TELOSYS GENERATOR
 *
 */
public class DoubleValueMapper extends XmlWrapperAncestor implements IXmlWrapper
{
    /*
     * Default constructor
     */
    public DoubleValueMapper()
    {
        super(DoubleValue.class);
    }
    
	//-----------------------------------------------------------------------------------
    /* 
     * Interface Implementation
     * @see org.objectweb.telosys.rpl.xml.IXmlWrapper
     */
    public Object createBean()
    {
        return new DoubleValue() ; 
    }

	//-----------------------------------------------------------------------------------
	/* 
	 * Interface Implementation
	 * @see org.telosys.xml.IXmlWrapper
	 * Set the values received in XML format
	 * ( the "XML entities" are processed by the parser => no conversion needed )
	 */
    public void setXmlFieldValue(Object oBean, String sName, String sValue)
    {
        if (oBean != null)
        {
            if (oBean instanceof DoubleValue)
            {
                DoubleValue vo = (DoubleValue) oBean;
				if (sName.equals( "value" ))
				{
			    	vo.setValue( getDouble(sName,sValue,0.0) );
					return;
				}
                //--- Unknown attribute
                throwException("unknown attribute '" + sName + "' in setXmlFieldValue(" + sName + "," + sValue + ")");
            }
            else
            {
                throwException("bean class = '" + oBean.getClass().getName() + "' ( DoubleValue expected )");
            }
        }
        else
        {
            throwException("bean is null");
        }
	}

	//-----------------------------------------------------------------------------------
	/*
	 * Interface Implementation
	 * @see org.telosys.xml.IXmlWrapper
	 * Serialized the bean in XML format
	 */
	public void toXml(PrintWriter out, Object oBean, String sTagName)
	{
        if (oBean != null)
        {
            if (oBean instanceof DoubleValue)
            {
                DoubleValue vo = (DoubleValue) oBean ;                
				out.print("<" + sTagName + " ");
				out.print( "value=\"" + vo.getValue() + "\" ");
				out.println("/>");
			}
            else
            {
                throwException("bean class = '" + oBean.getClass().getName() + "' ( DoubleValue expected )");
            }
		}
		else
		{
			out.print("<!-- " + sTagName + " = null -->");
		}
	}
	//-----------------------------------------------------------------------------------
}

